package base.thread.state;

/**
 * @Author: my_code
 * @Create: 2020-12-08 17:09
 *
 * priority
 * 优先级设定建议在start()调度前
 * 优先级低只是意味着获得调度的概率低，并不是优先级低就不会被调用了，这都看CPU的调度
 */
public class PriorityTest {
    public static void main(String[] args) {
        //main的优先级 ：5
        System.out.println(Thread.currentThread().getName() + "：——优先级——>" + Thread.currentThread().getPriority());

        MyPriority myPriority = new MyPriority();

        Thread thread1 = new Thread(myPriority,"A");
        Thread thread2 = new Thread(myPriority,"B");
        Thread thread7 = new Thread(myPriority,"C");
        Thread thread8 = new Thread(myPriority,"D");

        thread1.setPriority(1);
        thread2.setPriority(2);
        thread7.setPriority(7);
        thread8.setPriority(8);

        thread1.start();
        thread2.start();
        thread7.start();
        thread8.start();

    }
}
class MyPriority implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "——优先级——>" + Thread.currentThread().getPriority());
    }
}